package com.tanhua.backstage.controller;


import com.tanhua.backstage.service.SystemUserService;
import com.tanhua.common.utils.NoAuthorization;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@Slf4j
@RequestMapping("system/users")
public class SystemUsersController {
    @Autowired
    private SystemUserService systemUserService;
    /**
     * 用户登录校验
     * @param param 用户名 密码 验证码 uuid
     * @return
     */
    @NoAuthorization
    @PostMapping("login")
    public ResponseEntity<Object> login(@RequestBody Map<String,String> param){
        try {
            String token=this.systemUserService.login(param);
            Map<String,String> map1 = new HashMap<>();
            switch (token){
                case "1":
                    map1.put("message","用户名或密码错误~");
                    return ResponseEntity.status(500).body(map1);
                case "2":
                    map1.put("message","验证码错误~");
                    return ResponseEntity.status(500).body(map1);
                default:
                    break;
            }
            Map<String,String> map = new HashMap<>();
            map.put("token",token);
            return ResponseEntity.ok(map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
